package mortal.game.control
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import modules.*;
    import mortal.game.events.*;
    import mortal.game.model.*;
    import mortal.game.mvc.*;
    import mortal.game.rules.*;
    import mortal.game.scene.ai.*;
    import mortal.game.scene.events.*;
    import mortal.game.scene.player.entity.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class DailyController extends Controller
    {
        private var _giftModule:DailyGiftModule;

        public function DailyController()
        {
            
        }

        private function get giftModule() : DailyGiftModule
        {
            if (!this._giftModule)
            {
                this._giftModule = new DailyGiftModule();
            }
            return this._giftModule;
        }

        private function onPlayerTransportRes(param1:MessageBlock) : void
        {
            GameProxy.daily.onPlayerTransportRes(param1);
            GameProxy.taskProxy.updateReachLevelTask();
            
        }

        private function onPlayerLoopBookRes(param1:MessageBlock) : void
        {
            GameProxy.daily.onPlayerLoopBookRes(param1);
            GameProxy.taskProxy.addCycleTask();
            GameProxy.taskProxy.updateReachLevelTask();
            
        }

        private function onRunBussinessRes(param1:MessageBlock) : void
        {
            GameProxy.daily.onPlayerRunBussinessRes(param1);
            GameProxy.taskProxy.updateReachLevelTask();
            
        }

        private function onTreasureHuntRes(param1:MessageBlock) : void
        {
            GameProxy.daily.onTreasureHuntRes(param1);
            GameProxy.taskProxy.updateReachLevelTask();
            
        }

        private function onGuildTaskRes(param1:MessageBlock) : void
        {
            GameProxy.daily.onGuildTaskRes(param1);
            GameProxy.taskProxy.updateReachLevelTask();
            
        }

        private function onEvilTaskRes(param1:MessageBlock) : void
        {
            GameProxy.daily.onEvilTaskRes(param1);
            GameProxy.taskProxy.updateReachLevelTask();
            
        }

        private function onServerOpenDateRes(param1:MessageBlock) : void
        {
            GameProxy.daily.onServerOpenDateRes(param1);
            Dispatcher.dispatchEvent(new DataEvent(EventName.ServerOpenDay, cache.daily.serverOpenDay));
            
        }

        private function onPromotionCardInfoRes(param1:MessageBlock) : void
        {
            GameProxy.daily.onPromotionCardInfoRes(param1);
            Dispatcher.dispatchEvent(new DataEvent(EventName.DailyGiftInfoRes));
            
        }

        private function onGetTimeSuccessHandler(param1:Object) : void
        {
            cache.daily.offLineTime = int(param1.time);
            cache.daily.offLineExp = Number(param1.exp);
            if (!this.giftModule.isHide)
            {
                this.giftModule.refreshOffLine();
            }
            
        }

        private function onBackPackChangeHandler(param1:Object) : void
        {
            if (!this.giftModule.isHide)
            {
                this.giftModule.updatePackItem();
            }
            
        }

        private function onDailyGiftOpenHandler(event:DataEvent) : void
        {
            var _loc_2:int = 0;
            if (this.giftModule.isHide)
            {
                _loc_2 = 0;
                if (event.data != null)
                {
                    _loc_2 = int(event.data);
                }
                this.giftModule.show();
                this.giftModule.openTabByIndex(_loc_2);
            }
            else
            {
                this.giftModule.hide();
            }
            
        }

        private function onCopyNumChangeRes(param1:Object) : void
        {
            GameProxy.taskProxy.updateReachLevelTask();
            
        }

        private function onRoleLevelUpdate(param1:Object) : void
        {
            GameProxy.taskProxy.updateReachLevelTask();
            
        }

        private function onDailyActiveGoToHandler(event:DataEvent) : void
        {
            this.dailyActiveGoTo(event.data as DailyInfo);
            
        }

        private function dailyActiveGoTo(param1:DailyInfo) : void
        {
            var _loc_2:Array = null;
            if (param1 != null)
            {
                switch(param1.type)
                {
                    case DailyRule.CycleTask:
                    {
                        _loc_2 = cache.pack.backPackCache.getTypeItems(ECategory._ECategoryProp, EProp._EPropTaskLoopBook);
                        if (_loc_2.length <= 0)
                        {
                            Alert.show("没有循环任务书不能接取循环任务，可通过主线任务获得循环任务书。");
                        }
                        else
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.UseTaskFlushLoopBook));
                        }
                        break;
                    }
                    case DailyRule.TestField:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.BattlefieldShowIntroduce));
                        break;
                    }
                    default:
                    {
                        AIManager.onAutoPathAIControl(param1.target);
                        break;
                    }
                }
            }
            
        }

        private function onDailyActiveFlyToHandler(event:DataEvent) : void
        {
            this.dailyActiveFlyTo(event.data as DailyInfo);
            
        }

        private function dailyActiveFlyTo(param1:DailyInfo) : void
        {
            var _loc_2:Array = null;
            if (param1 != null)
            {
                switch(param1.type)
                {
                    case DailyRule.CycleTask:
                    {
                        _loc_2 = cache.pack.backPackCache.getTypeItems(ECategory._ECategoryProp, EProp._EPropTaskLoopBook);
                        if (_loc_2.length <= 0)
                        {
                            Alert.show("没有循环任务书不能接取循环任务，可通过主线任务获得循环任务书。");
                        }
                        else
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.UseTaskFlushLoopBook));
                        }
                        break;
                    }
                    default:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ConveyToReq, param1.target));
                        break;
                    }
                }
            }
            
        }

        override protected function initServer() : void
        {
            super.initServer();
            NetDispatcher.addCmdListener(EGateCommand._ECmdGatePlayerTransport, this.onPlayerTransportRes);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGatePlayerLoopBook, this.onPlayerLoopBookRes);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRunBusinessPlayer, this.onRunBussinessRes);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateServerOpenDate, this.onServerOpenDateRes);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGatePromotionCardInfo, this.onPromotionCardInfoRes);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGatePlayerTreasureHunt, this.onTreasureHuntRes);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGatePlayerGuildTask, this.onGuildTaskRes);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGatePlayerKillEvil, this.onEvilTaskRes);
            NetDispatcher.addCmdListener(ServerCommand.GetOfflineTimeSuccess, this.onGetTimeSuccessHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdate);
            NetDispatcher.addCmdListener(ServerCommand.Copy_CopyNumInfoChange, this.onCopyNumChangeRes);
            Dispatcher.addEventListener(EventName.DailyGiftOpen, this.onDailyGiftOpenHandler);
            Dispatcher.addEventListener(EventName.DailyActiveFlyTo, this.onDailyActiveFlyToHandler);
            Dispatcher.addEventListener(EventName.DailyActiveGoTo, this.onDailyActiveGoToHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.onBackPackChangeHandler);
            
        }

        override protected function initView() : IView
        {
            var _loc_1:* = new DailyModule();
            return _loc_1;
        }

    }
}
